<route lang="json5">
{
  style: {
    navigationStyle: 'custom',
    navigationBarTitleText: '软件版本',
    layout: false,
    'app-plus': {
      background: '#f8f8f8',
    },
  },
}
</route>

<template>
  <page-meta :root-font-size="setting.rootFontSize"></page-meta>
  <view class="page">
    <wd-navbar title="软件版本" :bordered="false" safeAreaInsetTop>
      <template #left>
        <wd-icon name="thin-arrow-left" size="22px" color="white" @click="goBack"></wd-icon>
      </template>
    </wd-navbar>
    <wd-cell-group border>
      <!-- <wd-cell :title="`当前软件版本：`" :value="`V${version}`" clickable></wd-cell> -->
      <wd-cell :title="`最新软件版本：`" :value="`V${newVersion}`" clickable></wd-cell>
      <!-- <view @click="handleCheckUpdate">检测更新</view> -->
      <wd-cell title="CID：" :value="clientid">
        <!-- <view @click="handleCheckUpdate">检测更新</view> -->
      </wd-cell>

      <view class="check-update-submit-item">
        <view
          :class="
            version && version != newVersion ? 'check-update-submit' : 'check-update-submit gray'
          "
          @click="handleCheckUpdate"
        >
          检测更新
        </view>
      </view>
      <view style="height: 40rpx"></view>
    </wd-cell-group>
  </view>
</template>

<script lang="ts" setup>
import { useSetting } from '@/stores/setting';
import { queryUpdate } from '@/service/sys';
import checkUpdate from '@/utils/check_update';

const setting = useSetting();
// const handleLogout = function () {
//   showModal({
//     content: '确定退出当前账号吗？',
//   }).then(() => {
//     uni.redirectTo({ url: '/pages/login/login' });
//   });
// };

const goBack = () => {
  uni.navigateBack();
};

const handleCheckUpdate = function () {
  checkUpdate();
};

const loading = ref('');
const version = ref('');
const newVersion = ref('');
const clientid = ref('');

const getVersion = async () => {
  const res = await queryUpdate({
    clientType: 1,
    appVersion: version.value,
  });
  console.log(res.data);
  if (res.data?.appVersion) {
    newVersion.value = res.data.appVersion;
  }
};

const init = function () {
  // #ifdef APP-PLUS
  plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => {
    version.value = widgetInfo.version;
    newVersion.value = version.value;
    getVersion();
  });
  plus.push.getClientInfoAsync(
    (info) => {
      clientid.value = info.clientid;
    },
    (err) => {
      console.log(err);
    },
  );
  // #endif
};
init();
</script>
<style scoped lang="scss">
page {
  background-color: #f8f8f8;
}

.page {
  height: 100%;
  background-color: #f8f8f8;
}

.wd-cell-group {
  ~ .wd-cell-group {
    margin-top: 24rpx;
  }
}
.check-update-submit-item {
  // padding: 20% 0 0%;
  padding: 50rpx 0 0;

  .check-update-submit {
    width: 60%;
    height: 70rpx;
    margin: 0 auto;
    font-size: 30rpx;

    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    text-align: center;

    // background-color: #0081ff;
    background-color: rgb(8 131 237);
    border-radius: 10rpx;
  }
  .check-update-submit.gray {
    background-color: rgba(128, 128, 128, 0.8);
  }
}
</style>
